package com.wephone.Student.ui;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterViewFlipper;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.wephone.Student.R;
import com.wephone.Student.bean.GroupOnlineListResponse;
import com.wephone.Student.bean.SearchCollegeResponse;
import com.wephone.Student.bean.UserListResponse;
import com.wephone.Student.bean.UserOnlineListResponse;
import com.wephone.Student.bean.data.CityData;
import com.wephone.Student.bean.data.CountryData;
import com.wephone.Student.bean.data.GroupInfo;
import com.wephone.Student.bean.data.MyLocationInfo;
import com.wephone.Student.bean.data.ProvinceData;
import com.wephone.Student.bean.data.SearchCollegeData;
import com.wephone.Student.bean.data.UserInfoData;
import com.wephone.Student.network.HttpClient;
import com.wephone.Student.network.MyResponseHandler;
import com.wephone.Student.util.Constants;
import com.wephone.Student.util.PullToRefreshView;
import com.wephone.Student.util.Util;
import com.wephone.Student.util.Utils;
import com.wephone.Student.util.PullToRefreshView.OnFooterRefreshListener;
import com.wephone.Student.util.PullToRefreshView.OnHeaderRefreshListener;
import com.wephone.Student.util.RoundImageView;
import com.wephone.Student.util.ShareReferenceUtil;
import com.wephone.Student.wheel.widget.OnWheelChangedListener;
import com.wephone.Student.wheel.widget.StringWheelAdapter;
import com.wephone.Student.wheel.widget.WheelView;
import com.etsy.android.grid.StaggeredGridView;

public class OnlineActivity extends BaseActivity {
	private static long backClickTime = -1;
	private PullToRefreshView pullToRefreshListView;
	private ListView listView;
	private ListViewAdapter adapter;
	private List<UserInfoData> results = new ArrayList<UserInfoData>();
	private List<UserInfoData> results4 = new ArrayList<UserInfoData>();
	private List<UserInfoData> results5 = new ArrayList<UserInfoData>();
	
	private PullToRefreshView pullToRefreshListView1;
	private ListView listView1;
	private ListViewAdapter1 adapter1;
	private int tab_id;
	private List<UserInfoData> results1 = new ArrayList<UserInfoData>();
	public static String country = "";
	public static String city = "";
	public static String school = "";
	public static String loc = "";
	public static String home = "";
	public static String type = "";
	public static String uGender = "";
	public static String uName = "";
	public static boolean needRefresh = true;
	public static boolean isDoSearch = false;
	public static int segid=0;
	public static OnlineActivity s_instance;
	private LinearLayout groupLayout,headerFirst,headerSecond;
	private PullToRefreshView pullToRefreshListView2;
	private StaggeredGridView gridView2;
	private GridViewAdapter adapter2;
	private List<GroupInfo> results2 = new ArrayList<GroupInfo>();
	private int countryIdx=1;
	private int provinceIdx=0;
	private int cityIdx = 0;
	private int locIdx1;
	private int locIdx2;
	private int homeIdx1;
	private int homeIdx2;
	private LinearLayout search_result;
	private TextView searchTxt;
	private RelativeLayout search_top;
	private PullToRefreshView pull_refresh_listview7;
	private ListView listview7;
	private List<UserInfoData> results7 = new ArrayList<UserInfoData>();
	private ListViewAdapter1 adapter7;
	private PullToRefreshView pull_refresh_listview8;
	private StaggeredGridView gridview3;
	private GridViewAdapter adapter8;
	private List<GroupInfo> results8 = new ArrayList<GroupInfo>();
	
	private MyResponseHandler getHandler(){
		MyResponseHandler handler = new MyResponseHandler(OnlineActivity.this,UserListResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				if(getDataSuccess){
					UserListResponse res = (UserListResponse)response;
					adapter.hasMore = true;
					adapter.pageIdx++;
					results.clear();
					UserInfoData data0= new UserInfoData();
					data0.setuId("0");
					data0.setuName("为你推荐");
					results.add(data0);
					for(UserInfoData infoData:res.getData()){
						if(infoData.getuId().equals(BaseActivity.getMyInfo(getApplicationContext()).getuId())){
							continue;
						}else if(infoData.getuType()!=null && !infoData.getuType().equals("member")){
							continue;
						}
						results.add(infoData);
					}
					adapter.notifyDataSetChanged();
					UserInfoData data1= new UserInfoData();
					data1.setuId("0");
					data1.setuName("最新登录");
					results.add(data1);
					getData4(adapter.pageIdx-1, getHandler4(),10);
				}
			}
		};
		return handler;
	}
	
	private MyResponseHandler getHandler4(){
		MyResponseHandler handler = new MyResponseHandler(OnlineActivity.this,UserListResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				if(getDataSuccess){
					UserListResponse res = (UserListResponse)response;
					adapter.hasMore = true;
					adapter.pageIdx++;
					for(UserInfoData infoData:res.getData()){
						if(infoData.getuId().equals(BaseActivity.getMyInfo(getApplicationContext()).getuId())){
							continue;
						}else if(infoData.getuType()!=null && !infoData.getuType().equals("member")){
							continue;
						}
						results.add(infoData);
					}
					adapter.notifyDataSetChanged();
				}
			}
		};
		return handler;
	}

	
	private MyResponseHandler getHandler1(){
		MyResponseHandler handler = new MyResponseHandler(OnlineActivity.this,UserOnlineListResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				if(getDataSuccess){
					UserOnlineListResponse res = (UserOnlineListResponse)response;
					if(adapter1.pageIdx>=res.getTotalPage() || res.getData().size()<Constants.PAGE_SIZE){
						adapter1.hasMore = false;
					}else{
						adapter1.pageIdx++;
					}
					for(UserInfoData infoData:res.getData()){
						if(infoData.getuId().equals(BaseActivity.getMyInfo(getApplicationContext()).getuId())){
							continue;
						}else if(infoData.getuType()!=null && !infoData.getuType().equals("member")){
							continue;
						}
						results1.add(infoData);
					}
					adapter1.notifyDataSetChanged();
				}
			}
		};
		return handler;
	}

	private MyResponseHandler getHandler2(){
		MyResponseHandler handler = new MyResponseHandler(OnlineActivity.this,GroupOnlineListResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				System.out.println("---------Success:"+getDataSuccess);
				if(getDataSuccess){
					GroupOnlineListResponse res = (GroupOnlineListResponse)response;
//					
					if(adapter2.pageIdx>=res.getTotalPage() || res.getData().size()<Constants.PAGE_SIZE){
						adapter2.hasMore = false;
					}else{
						adapter2.pageIdx++;
					}
					System.out.println("---------Groups:"+res.getTotalPage());
					//results2.clear();
					for(GroupInfo infoData:res.getData()){
						results2.add(infoData);
					}
					adapter2.notifyDataSetChanged();
					System.out.println("---------Groups1:"+res.getTotalPage());
				}
			}
		};
		return handler;
	}

	private MyResponseHandler getHandler8(){
		MyResponseHandler handler = new MyResponseHandler(OnlineActivity.this,GroupOnlineListResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				System.out.println("---------Success:"+getDataSuccess);
				if(getDataSuccess){
					GroupOnlineListResponse res = (GroupOnlineListResponse)response;
//					
					if(adapter8.pageIdx>=res.getTotalPage() || res.getData().size()<Constants.PAGE_SIZE){
						adapter8.hasMore = false;
					}else{
						adapter8.pageIdx++;
					}
					System.out.println("---------Groups:"+res.getTotalPage());
					//results2.clear();
					for(GroupInfo infoData:res.getData()){
						results8.add(infoData);
					}
					adapter8.notifyDataSetChanged();
					System.out.println("---------Groups1:"+res.getTotalPage());
				}
			}
		};
		return handler;
	}
	
	private MyResponseHandler getHandler7(){
		MyResponseHandler handler = new MyResponseHandler(OnlineActivity.this,UserOnlineListResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
				if(getDataSuccess){
					UserOnlineListResponse res = (UserOnlineListResponse)response;
					if(adapter7.pageIdx>=res.getTotalPage() || res.getData().size()<Constants.PAGE_SIZE){
						adapter7.hasMore = false;
					}else{
						adapter7.pageIdx++;
					}
					for(UserInfoData infoData:res.getData()){
						if(infoData.getuId().equals(BaseActivity.getMyInfo(getApplicationContext()).getuId())){
							continue;
						}else if(infoData.getuType()!=null && !infoData.getuType().equals("member")){
							continue;
						}
						results7.add(infoData);
					}
					adapter7.notifyDataSetChanged();
				}
			}
		};
		return handler;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_online);
		s_instance = OnlineActivity.this;
		tab_id=1;
		init();
		init1();
		init2();
	}
	
	public void showTab(int tab_id){
		System.out.println("NOTab"+tab_id);
		this.tab_id = tab_id;
		InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
	    //Find the currently focused view, so we can grab the correct window token from it.
	    View view = this.getCurrentFocus();
	    //If no view currently has focus, create a new one, just so we can grab a window token from it
	    if(view == null) {
	        view = new View(this);
	    }
	    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
		switch(tab_id){
		case 1:
			findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
			pullToRefreshListView.setVisibility(View.VISIBLE);
			pullToRefreshListView1.setVisibility(View.GONE);
			groupLayout.setVisibility(View.GONE);
			search_all.setVisibility(View.GONE);
			search_result.setVisibility(View.GONE);
			getData(1, getHandler());
			
			break;
		case 2:
			findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
			pullToRefreshListView1.setVisibility(View.VISIBLE);
			pullToRefreshListView.setVisibility(View.GONE);
			groupLayout.setVisibility(View.GONE);
			search_all.setVisibility(View.GONE);
			search_result.setVisibility(View.GONE);
			getData1(1, getHandler1());
			break;
		case 3:
			findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
			pullToRefreshListView.setVisibility(View.GONE);
			pullToRefreshListView1.setVisibility(View.GONE);
			groupLayout.setVisibility(View.VISIBLE);
			RequestParams params1 = new RequestParams();
			params1.put("Page", "1");
			params1.put("PageSize", ""+Constants.PAGE_SIZE);
			search_all.setVisibility(View.GONE);
			search_result.setVisibility(View.GONE);
			HttpClient.getInstance().get(Constants.API_CHART_LIST_URL, params1, getHandler2());
			break;
		case 4:
			
			pullToRefreshListView.setVisibility(View.GONE);
			pullToRefreshListView1.setVisibility(View.GONE);
			groupLayout.setVisibility(View.GONE);
			search_all.setVisibility(View.VISIBLE);
			search_result.setVisibility(View.GONE);
			break;
		}
		/*
		View view = this.getCurrentFocus();
		if (view != null) {  
		InputMethodManager imm = (InputMethodManager)getSystemService(
		      Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
		}
		*/
		/*
		getWindow().setSoftInputMode(
			    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
			);
		InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
		*/
		
	}
	
	private void init(){
		listView = (ListView)findViewById(R.id.listview);
		adapter = new ListViewAdapter();
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new ListView.OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Bundle bundle = new Bundle();
				bundle.putSerializable("userData", results.get(arg2));
				startActivity(new Intent(getApplicationContext(),UserInfoDetailActivity.class).putExtras(bundle));
			}});
		
		pullToRefreshListView = (PullToRefreshView)findViewById(R.id.pull_refresh_listview);
		pullToRefreshListView.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				adapter.hasMore = true;
				adapter.pageIdx = 1;
				results.clear();
				getData(1, getHandler());
				//getData4(1, getHandler4());
			}
		});
		pullToRefreshListView.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				if(!adapter.hasMore){
					pullToRefreshListView.onFooterRefreshComplete();
					return;
				}
				getData4(adapter.pageIdx, getHandler4(),10);
				//getData4(adapter4.pageIdx, getHandler4());
			}
		});
		init_search();
		OnlineActivity.needRefresh = true;
	}
	private void getData(int page,MyResponseHandler handler){
		System.out.println("getData:111");
		RequestParams params = new RequestParams();
		params.put("uId", BaseActivity.getMyInfo(getApplicationContext()).getuId());
		params.put("page", ""+page);
		HttpClient.getInstance().get(Constants.API_GET_USER_REC, params, handler);
	}
	private void getData1(int page,MyResponseHandler handler){
		
		RequestParams params = new RequestParams();
		params.put("Page", ""+page);
		params.put("PageSize", ""+Constants.PAGE_SIZE);
		
		params.put("uGpsX", ShareReferenceUtil.getLocationLatitude(getApplicationContext()));
		params.put("uGpsY", ShareReferenceUtil.getLocationLontitude(getApplicationContext()));
		params.put("uLength", "50000");
		
		HttpClient.getInstance().get(Constants.API_GET_USER_LIST_URL, params,handler);
	}
	//搜索会员
	private void getData5(int page,MyResponseHandler handler){
		findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
		RequestParams params = new RequestParams();
		params.put("Page", ""+page);
		params.put("PageSize", ""+Constants.PAGE_SIZE);
		if(isDoSearch){
			params.put("uGpsX", "0");
			params.put("uGpsY", "0");
			params.put("uLength", "0");
		}
		String search="";
		if(!TextUtils.isEmpty(country)){
			params.put("country", country);
			search+=country+",";
		}else{
			params.put("country", "");
		}
		if(!TextUtils.isEmpty(city)){
			params.put("city", city);
			search+=city+",";
		}else{
			params.put("city", "");
		}
		school = peo_school_txt.getText().toString();
		if(!TextUtils.isEmpty(school)){
			params.put("school", school);
			search+=school+",";
		}else{
			params.put("school", "");
		}
		if(!TextUtils.isEmpty(loc)){
			params.put("loc", loc);
			search+=loc+",";
		}else{
			params.put("loc", "");
		}
		if(!TextUtils.isEmpty(home)){
			params.put("home", home);
			search+=home+",";
		}else{
			params.put("home", "");
		}
		if(!TextUtils.isEmpty(uGender)){
			params.put("uGender", uGender);
			if(uGender=="0"){
				search+="男,";
			}else if(uGender=="1"){
				search+="女,";
			}
		}else{
			params.put("uGender", "-1");
		}
		if(!TextUtils.isEmpty(type)){
			params.put("type", type);
			if(type.equals("Foreign")){
				search+="国外留学生,";
			}else if(type.equals("Returnees")){
				search+="海归留学生,";
			}else{
				search+="想要出国的,";
			}
		}else{
			params.put("type", "");
		}
		if(!TextUtils.isEmpty(uName)){
			params.put("uName", uName);
			search+=uName+",";
		}else{
			params.put("uName", "");
		}
		if(search.length()>0){
			search = search.substring(0, search.length()-1);
			this.searchTxt.setText(search);
		}else{
			this.searchTxt.setText("");
		}
		
		
		HttpClient.getInstance().get(Constants.API_GET_USER_LIST_URL, params,handler);
	}
	
	//搜索群组
		private void getData8(int page,MyResponseHandler handler){
			findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
			RequestParams params = new RequestParams();
			params.put("Page", ""+page);
			params.put("PageSize", ""+Constants.PAGE_SIZE);
			String search="";
			if(!TextUtils.isEmpty(group_no.getText().toString())){
				params.put("groupid", group_no.getText().toString());
				search+=group_no.getText().toString()+",";
			}
			if(!TextUtils.isEmpty(search_group_type)){
				params.put("type", search_group_type);
				search+=search_group_type+",";
			}
			if(!TextUtils.isEmpty(group_name.getText().toString())){
				params.put("name", group_name.getText().toString());
				search+=group_name.getText().toString()+",";
			}
			if(!TextUtils.isEmpty(search_group_loc)){
				params.put("clog", search_group_loc);
				search+=search_group_loc+",";
			}
			if(search.length()>0){
				search = search.substring(0, search.length()-1);
				this.searchTxt.setText(search);
			}else{
				this.searchTxt.setText("");
			}
			
			HttpClient.getInstance().get(Constants.API_SEARCH_CHART_LIST, params, getHandler8());
		}
		
	
	private void getData4(int page,MyResponseHandler handler,int pageSize){
		System.out.println("getData:111");
		RequestParams params = new RequestParams();
		
		params.put("uId", BaseActivity.getMyInfo(getApplicationContext()).getuId());
		params.put("Page", ""+page);
		params.put("PageSize", ""+pageSize);
		
		HttpClient.getInstance().get(Constants.API_GET_USER_LIST_URL, params, handler);
	}
	private void init1(){
		listView1 = (ListView)findViewById(R.id.listview1);
		adapter1 = new ListViewAdapter1();
		adapter1.setData(results1);
		listView1.setAdapter(adapter1);
		listView1.setOnItemClickListener(new ListView.OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Bundle bundle = new Bundle();
				bundle.putSerializable("userData", results1.get(arg2));
				startActivity(new Intent(getApplicationContext(),UserInfoDetailActivity.class).putExtras(bundle));
			}});
		pullToRefreshListView1 = (PullToRefreshView)findViewById(R.id.pull_refresh_listview1);
		pullToRefreshListView1.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				adapter1.hasMore = true;
				adapter1.pageIdx = 1;
				results1.clear();
				
				getData1(1, getHandler1());
			}
		});
		pullToRefreshListView1.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				if(!adapter1.hasMore){
					pullToRefreshListView1.onFooterRefreshComplete();
					return;
				}
				getData1(adapter1.pageIdx, getHandler1());
			}
		});
		
		OnlineActivity.needRefresh = true;
	}
	private void init2(){
		groupLayout=(LinearLayout)findViewById(R.id.groupLayout);
		headerFirst = (LinearLayout)findViewById(R.id.headerFirst);
		headerSecond = (LinearLayout)findViewById(R.id.headerSecond);
		
		headerFirst.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivity(new Intent(getApplicationContext(),AllRecGroupsActivity.class));
			}
		});
		
		headerSecond.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivity(new Intent(getApplicationContext(),NewGroupActivity1.class));
			}
		});
		
		gridView2 = (StaggeredGridView)findViewById(R.id.gridview2);
		adapter2 = new GridViewAdapter();
		adapter2.setData(results2);
		gridView2.setAdapter(adapter2);
		gridView2.setOnItemClickListener(new AdapterView.OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Bundle bundle = new Bundle();
				bundle.putSerializable("groupData", results2.get(arg2));
				startActivity(new Intent(getApplicationContext(),GroupInfoDetailActivity.class).putExtras(bundle));
			}});
		
		pullToRefreshListView2 = (PullToRefreshView)findViewById(R.id.pull_refresh_listview2);
		pullToRefreshListView2.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				adapter2.hasMore = true;
				adapter2.pageIdx = 1;
				results2.clear();
				adapter2.notifyDataSetChanged();
				
				RequestParams params = new RequestParams();
				params.put("Page", "1");
				params.put("PageSize", ""+Constants.PAGE_SIZE);
				
				HttpClient.getInstance().get(Constants.API_CHART_LIST_URL, params, getHandler2());
			}
		});
		pullToRefreshListView2.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				if(!adapter2.hasMore){
					pullToRefreshListView2.onFooterRefreshComplete();
					return;
				}
				RequestParams params = new RequestParams();
				params.put("Page", ""+adapter2.pageIdx);
				params.put("PageSize", ""+Constants.PAGE_SIZE);
				HttpClient.getInstance().get(Constants.API_CHART_LIST_URL, params, getHandler2());
			}
		});
		
		OnlineActivity.needRefresh = true;
		
	}
	@Override
	protected void onResume() {
		super.onResume();
//		System.out.println("----------resume--------------------");
		if(needRefresh ){
			needRefresh = false;
			if(tab_id==1 || results.size()==0){
			results.clear();
			
			findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
			adapter.hasMore = true;
			adapter.pageIdx = 1;
			
			RequestParams params = new RequestParams();
			params.put("Page", "1");
			params.put("PageSize", ""+Constants.PAGE_SIZE);
			if(isDoSearch){
//				isDoSearch = false;
				params.put("uGpsX", "0");
				params.put("uGpsY", "0");
				params.put("uLength", "0");
			}else{
//				System.out.println("--uGpsX--"+ShareReferenceUtil.getLocationLatitude(getApplicationContext()));
//				System.out.println("--uGpsY--"+ShareReferenceUtil.getLocationLontitude(getApplicationContext()));
				params.put("uGpsX", ShareReferenceUtil.getLocationLatitude(getApplicationContext()));
				params.put("uGpsY", ShareReferenceUtil.getLocationLontitude(getApplicationContext()));
//				params.put("uGpsX", "-33.890640");
//				params.put("uGpsY", "151.249512");
				params.put("uLength", "50000");
			}
			if(!TextUtils.isEmpty(type)){
				params.put("type", type);
			}else{
				params.put("type", "");
			}
			if(!TextUtils.isEmpty(uName)){
				params.put("uName", uName);
			}else{
				params.put("uName", "");
			}
			if(!TextUtils.isEmpty(country)){
				params.put("country", country);
			}else{
				params.put("country", "");
			}
			if(!TextUtils.isEmpty(city)){
				params.put("city", city);
			}else{
				params.put("city", "");
			}
			school = peo_school_txt.getText().toString();
			if(!TextUtils.isEmpty(school)){
				params.put("school", school);
			}else{
				params.put("school", "");
			}
			if(!TextUtils.isEmpty(loc)){
				params.put("loc", loc);
			}else{
				params.put("loc", "");
			}
			if(!TextUtils.isEmpty(home)){
				params.put("home", home);
			}else{
				params.put("home", "");
			}
			if(!TextUtils.isEmpty(uGender)){
				params.put("uGender", uGender);
			}else{
				params.put("uGender", "-1");
			}
//			System.out.println("-----gender-----"+gender);
//			System.out.println("-----uGpsX-----"+ShareReferenceUtil.getLocationLatitude(getApplicationContext()));
//			System.out.println("-----uGpsY-----"+ShareReferenceUtil.getLocationLontitude(getApplicationContext()));
//			System.out.println("country:"+country+"  city:"+city+"  school:"+school);
			HttpClient.getInstance().get(Constants.API_GET_USER_REC, params, getHandler());
			}else if(tab_id==3){
				results2.clear();
				adapter2.notifyDataSetChanged();
				adapter2.hasMore = true;
				adapter2.pageIdx = 1;
				
				RequestParams params1 = new RequestParams();
				
				params1.put("Page", "1");
				params1.put("PageSize", ""+Constants.PAGE_SIZE);
				HttpClient.getInstance().get(Constants.API_CHART_LIST_URL, params1, getHandler2());
			}
		//	HttpClient.getInstance().get(Constants.API_GET_USER_LIST_URL, params, getHandler1());
			
		}
	}
	
	private DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.default_user_logo)
    .showImageOnFail(R.drawable.default_user_logo)
    .bitmapConfig(Bitmap.Config.ARGB_8888)
    .cacheInMemory()
    .cacheOnDisc()
//    .displayer(new RoundedBitmapDisplayer(1000))
    .build();
	private DisplayImageOptions options1 = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.big_logo)
    .showImageOnFail(R.drawable.big_logo)
    .bitmapConfig(Bitmap.Config.ARGB_8888)
    .cacheInMemory()
    .cacheOnDisc()
//    .displayer(new RoundedBitmapDisplayer(1000))
    .build();

	private class ListViewAdapter extends BaseAdapter{
		public int pageIdx = 1;
		public boolean hasMore = true;
		private SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		private Gson gson = new Gson();
		
		private static final int TYPE_ITEM = 0;
		private static final int TYPE_SEPARATOR = 1;
		
		
		@Override
		public int getCount() {
			return results.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}
		@Override
		public int getItemViewType(int position) {
			UserInfoData userData = results.get(position);
			if(userData.getuId().equals("0")){
				return TYPE_SEPARATOR;
			}else{
				return TYPE_ITEM;
			}
			//return sectionHeader.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
		}

		@Override
		public int getViewTypeCount() {
			return 2;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			int rowType = getItemViewType(position);
			if(rowType == TYPE_ITEM){
			if(convertView==null){
				convertView = getLayoutInflater().inflate(R.layout.include_online_list_item, null);
			}
			UserInfoData userData = results.get(position);
			TextView itemName = (TextView)convertView.findViewById(R.id.item_name);
			itemName.setText(userData.getuName());
			TextView itemCountry = (TextView)convertView.findViewById(R.id.item_country);
//			itemCountry.setText(sdf.format(new Date(Long.parseLong(userData.getuTS())*1000)));
			TextView universityText = (TextView)convertView.findViewById(R.id.item_university);
//			universityText.setText(userData.getuConstellation());
			TextView itemSign = (TextView)convertView.findViewById(R.id.item_signature);
			itemSign.setText(userData.getuSign());
			
			TextView itemDistance =(TextView)convertView.findViewById(R.id.item_distance);
			//itemDistance.setText(userData.getU)
			ImageView item_now = (ImageView)convertView.findViewById(R.id.item_now);
			
			convertView.findViewById(R.id.item_distance).setVisibility(View.GONE);
			convertView.findViewById(R.id.dddd).setVisibility(View.GONE);
			
			if(!TextUtils.isEmpty(userData.getuLocDetail())){
//				System.out.println("---uid---"+userData.getuId());
//				System.out.println("---locdetail---"+userData.getuLocDetail());
				MyLocationInfo locInfo = gson.fromJson(userData.getuLocDetail(), MyLocationInfo.class);
				if(locInfo.getType().equals("PlanGoOut")){
					universityText.setText(locInfo.getToschool());
					itemCountry.setText("中国 "+locInfo.getCity());
				}else if(locInfo.getType().equals("Returnees")){
					if(!TextUtils.isEmpty(locInfo.getSchool2())){
						universityText.setText(locInfo.getSchool1()+","+locInfo.getSchool2());
					}else{
						universityText.setText(locInfo.getSchool1());
					}
					itemCountry.setText(locInfo.getLoc());
				}else{
					universityText.setText(locInfo.getSchool());
					itemCountry.setText(locInfo.getCity()+" "+locInfo.getCountry());
				}
			}
			if(userData.getuLocType().equals("1")){
				item_now.setImageResource(R.drawable.inchina);
			}else if(userData.getuLocType().equals("2")){
				item_now.setImageResource(R.drawable.goabroad);
			}else{
				item_now.setImageResource(R.drawable.abroad);
			}
			TextView genderText = (TextView)convertView.findViewById(R.id.item_gender_text);
			ImageView genderImage = (ImageView)convertView.findViewById(R.id.item_gender);
			if(userData.getuGender().equals("0")){
				genderImage.setImageResource(R.drawable.online_male);
				genderText.setText(userData.getuAge());
			}else{
				genderImage.setImageResource(R.drawable.online_female);
				genderText.setText(userData.getuAge());
			}
			
			RoundImageView itemImage = (RoundImageView)convertView.findViewById(R.id.item_image);
			if(!TextUtils.isEmpty(userData.getuIcon())){
				String endStr = userData.getuIcon().substring(userData.getuIcon().lastIndexOf("."));
				imageLoader.displayImage(Constants.IMAGE_PHOTO_SERVER_PATH+userData.getuIcon().replace(endStr, "_150_150"+endStr), itemImage, options);
//				imageLoader.displayImage(Constants.IMAGE_PHOTO_SERVER_PATH+userData.getuIcon(), itemImage, options);
			}else{
				itemImage.setImageResource(R.drawable.default_user_logo);
			}
			}else{
				if(convertView==null){
					convertView = getLayoutInflater().inflate(R.layout.include_group_member_header, null);
				}
				UserInfoData userData = results.get(position);
				TextView groupName = (TextView)convertView.findViewById(R.id.groupName);
				groupName.setText(userData.getuName());
				
				TextView groupNum = (TextView)convertView.findViewById(R.id.groupNum);
				//if(userData.getuAge().equals("0")){
					groupNum.setVisibility(View.GONE);
				//}
			}
			return convertView;
		}		
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			 long nowTime = System.currentTimeMillis();
				if(backClickTime<=0 || nowTime-backClickTime>2000){
					backClickTime = nowTime;
					Toast.makeText(getApplicationContext(), "再按一次 退出程序", Toast.LENGTH_SHORT).show();
				}else{
					finish();
				}
			return true; 
        }
        return super.onKeyDown(keyCode, event); 
	}
	
	
	private class GridViewAdapter extends BaseAdapter{
		public int pageIdx = 1;
		public boolean hasMore = true;
		private SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		private Gson gson = new Gson();
		private List<GroupInfo> datas;
		
		public void setData(List<GroupInfo> data){
			this.datas = data;
		}
		
		@Override
		public int getCount() {
			System.out.println("results2:"+datas.size());
			return datas.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			//System.out.println("getView111:");
			if(convertView==null){
				convertView = getLayoutInflater().inflate(R.layout.group_view_item, null);
			}
			
			GroupInfo groupData = datas.get(position);
			System.out.println("getView:"+groupData.getName());
			TextView itemName = (TextView)convertView.findViewById(R.id.groupName);
			itemName.setText(groupData.getName());
			TextView itemDesc = (TextView)convertView.findViewById(R.id.groupDesc);
			itemDesc.setText(groupData.getContent());
			
			TextView groupCountry = (TextView)convertView.findViewById(R.id.groupCountry);
			groupCountry.setText(groupData.getClog());
			TextView groupNum = (TextView)convertView.findViewById(R.id.groupNum);
			groupNum.setText(groupData.getNownum()+"/"+groupData.getMaxnum());
			
			final ImageView item_pic = (ImageView)convertView.findViewById(R.id.group_pic);
			
			ImageView is_rec = (ImageView)convertView.findViewById(R.id.is_rec);
			
			if(groupData.getIsrec().equals("0")){
				is_rec.setVisibility(View.GONE);
			}else{
				is_rec.setVisibility(View.VISIBLE);
			}
			
			
			ImageView now_num_line = (ImageView)convertView.findViewById(R.id.now_num_line);
			
			float real_width = Util.getScreenWidth(getApplicationContext())*Integer.parseInt(groupData.getNownum())/Integer.parseInt(groupData.getMaxnum());
			
			now_num_line.getLayoutParams().width = (int)Util.convertDpToPixel(real_width*2, getApplicationContext());
			
			Resources res = getResources();  
		    Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.big_logo);  
			final Bitmap tempBitmap1 = Utils.getFixedBitMap(bmp,getApplicationContext(),2);
			
			if(!TextUtils.isEmpty(groupData.getPic())){
				//String endStr = groupData.getPic().substring(groupData.getPic().lastIndexOf("."));
				imageLoader.displayImage(Constants.IMAGE_PHOTO_SERVER_PATH+groupData.getPic(),item_pic, options1,new ImageLoadingListener() {
					
					@Override
					public void onLoadingCancelled(String arg0, View arg1) {
						// TODO Auto-generated method stub
						
					}
					@Override
					public void onLoadingComplete(String arg0, View arg1,
							Bitmap arg2) {
						// TODO Auto-generated method stub
						Bitmap tempBitmap = Utils.getFixedBitMap(arg2,getApplicationContext(),2);
						if(tempBitmap != null) {
							item_pic.setImageBitmap(tempBitmap);
						}
					}

					@Override
					public void onLoadingFailed(String arg0, View arg1,
							FailReason arg2) {
						// TODO Auto-generated method stub
						if(tempBitmap1 != null) {
							item_pic.setImageBitmap(tempBitmap1);
						}
					}

					@Override
					public void onLoadingStarted(String arg0, View arg1) {
						// TODO Auto-generated method stub
						
					}
				});		
			}else{
				
				if(tempBitmap1 != null) {
					item_pic.setImageBitmap(tempBitmap1);
				}
			}
			return convertView;
		}		
	}
	
	//搜索界面
	private LinearLayout search_all,people_body,group_body;
	private RelativeLayout search_people,search_group;
	private TextView selector_txt1,selector_txt2;
	private ImageView selector_line1,selector_line2;
	private Button btn_do_search;
	private int search_which=0;
	private TextView peo_country_txt,peo_city_txt,peo_sex_txt,peo_type_txt,peo_location_txt,peo_home_town_txt,group_type_txt,group_location_txt;
	private AutoCompleteTextView peo_school_txt;
	private long searchTime;
	private EditText people_name,group_name,group_no;
	private String search_group_loc="";
	public static String search_group_type="";
	private List<SearchCollegeData> searchCollegeList = new ArrayList<SearchCollegeData>();
	
	private void init_search(){
		btn_do_search = (Button)findViewById(R.id.btn_do_search);
		search_all = (LinearLayout)findViewById(R.id.search_all);
		people_body =(LinearLayout)findViewById(R.id.people_body);
		group_body = (LinearLayout)findViewById(R.id.group_body);
		search_people = (RelativeLayout)findViewById(R.id.search_people);
		search_group = (RelativeLayout)findViewById(R.id.search_group);
		selector_txt1 = (TextView)findViewById(R.id.selector_txt1);
		selector_txt2 = (TextView)findViewById(R.id.selector_txt2);
		selector_line1 = (ImageView)findViewById(R.id.selector_line1);
		selector_line2 = (ImageView)findViewById(R.id.selector_line2);
		peo_sex_txt = (TextView)findViewById(R.id.peo_sex_txt);
		peo_country_txt =(TextView)findViewById(R.id.peo_country_txt);
		peo_city_txt =(TextView)findViewById(R.id.peo_city_txt);
		peo_location_txt =(TextView)findViewById(R.id.peo_location_txt);
		peo_home_town_txt =(TextView)findViewById(R.id.peo_home_town_txt);
		peo_type_txt = (TextView)findViewById(R.id.peo_type_txt);
		searchTxt = (TextView)findViewById(R.id.searchTxt);
		group_location_txt = (TextView)findViewById(R.id.group_location_txt);
		group_type_txt = (TextView)findViewById(R.id.group_type_txt);
		search_top=(RelativeLayout)findViewById(R.id.search_top);
		people_name =(EditText)findViewById(R.id.people_name);
		group_name = (EditText)findViewById(R.id.group_name);
		group_no = (EditText)findViewById(R.id.group_no);
		
		search_result = (LinearLayout)findViewById(R.id.search_result);
		listview7 = (ListView)findViewById(R.id.listview7);
		adapter7 = new ListViewAdapter1();
		adapter7.setData(results7);
		listview7.setAdapter(adapter7);
		listview7.setOnItemClickListener(new ListView.OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Bundle bundle = new Bundle();
				bundle.putSerializable("userData", results7.get(arg2));
				startActivity(new Intent(getApplicationContext(),UserInfoDetailActivity.class).putExtras(bundle));
			}});
		pull_refresh_listview7 = (PullToRefreshView)findViewById(R.id.pull_refresh_listview7);
		pull_refresh_listview7.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				adapter7.hasMore = true;
				adapter7.pageIdx = 1;
				results7.clear();
				
				getData5(1, getHandler7());
			}
		});
		pull_refresh_listview7.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				if(!adapter7.hasMore){
					pull_refresh_listview7.onFooterRefreshComplete();
					return;
				}
				getData5(adapter7.pageIdx, getHandler7());
			}
		});
		
		
		gridview3 = (StaggeredGridView)findViewById(R.id.gridview3);
		adapter8 = new GridViewAdapter();
		adapter8.setData(results8);
		gridview3.setAdapter(adapter8);
		gridview3.setOnItemClickListener(new GridView.OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Bundle bundle = new Bundle();
				bundle.putSerializable("groupData", results8.get(arg2));
				startActivity(new Intent(getApplicationContext(),GroupInfoDetailActivity.class).putExtras(bundle));
			}});
		pull_refresh_listview8 = (PullToRefreshView)findViewById(R.id.pull_refresh_listview8);
		pull_refresh_listview8.setOnHeaderRefreshListener(new OnHeaderRefreshListener() {
			@Override
			public void onHeaderRefresh(PullToRefreshView view) {
				adapter8.hasMore = true;
				adapter8.pageIdx = 1;
				results8.clear();
				adapter8.notifyDataSetChanged();
				
				getData8(1,getHandler8());
				/*
				RequestParams params = new RequestParams();
				params.put("Page", "1");
				params.put("PageSize", ""+Constants.PAGE_SIZE);
				
				HttpClient.getInstance().get(Constants.API_CHART_LIST_URL, params, getHandler8());
				*/
			}
		});
		
		pull_refresh_listview8.setOnFooterRefreshListener(new OnFooterRefreshListener() {
			@Override
			public void onFooterRefresh(PullToRefreshView view) {
				if(!adapter8.hasMore){
					pull_refresh_listview8.onFooterRefreshComplete();
					return;
				}
				/*
				RequestParams params = new RequestParams();
				params.put("Page", ""+adapter8.pageIdx);
				params.put("PageSize", ""+Constants.PAGE_SIZE);
				HttpClient.getInstance().get(Constants.API_CHART_LIST_URL, params, getHandler8());
				*/
				getData8(adapter8.pageIdx,getHandler8());
			}
		});
		
		search_people.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(search_which ==0){
					return;
				}
				search_which = 0;
				selector_txt1.setTextColor(getResources().getColor(R.color.orange));
				selector_line1.setVisibility(View.VISIBLE);
				
				selector_txt2.setTextColor(getResources().getColor(R.color.default_black));
				selector_line2.setVisibility(View.GONE);
				people_body.setVisibility(View.VISIBLE);
				group_body.setVisibility(View.GONE);
			}
		});
		search_group.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(search_which ==1){
					return;
				}
				search_which = 1;
				selector_txt2.setTextColor(getResources().getColor(R.color.orange));
				selector_line2.setVisibility(View.VISIBLE);
				
				selector_txt1.setTextColor(getResources().getColor(R.color.default_black));
				selector_line1.setVisibility(View.GONE);
				group_body.setVisibility(View.VISIBLE);
				people_body.setVisibility(View.GONE);
			}
		});
		
		btn_do_search.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				OnlineActivity.isDoSearch = true;
				search_result.setVisibility(View.VISIBLE);
				search_all.setVisibility(View.GONE);
				if(search_which==0){//搜索人
					uName = people_name.getText().toString();
					pull_refresh_listview7.setVisibility(View.VISIBLE);
					pull_refresh_listview8.setVisibility(View.GONE);
					results7.clear();
					getData5(1,getHandler7());
				}else{//搜索群
					pull_refresh_listview7.setVisibility(View.GONE);
					pull_refresh_listview8.setVisibility(View.VISIBLE);
					results8.clear();
					adapter8.notifyDataSetChanged();
					getData8(1,getHandler8());
				}
			}
		});
		
		search_top.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				search_result.setVisibility(View.GONE);
				search_all.setVisibility(View.VISIBLE);
				
			}
		});
		
		findViewById(R.id.rel_country).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				showChooseCountryDialog(getString(R.string.dialog_online_filter_hint_1), peo_country_txt,peo_city_txt);
			}
		});
		findViewById(R.id.rel_city).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(TextUtils.isEmpty(peo_country_txt.getText().toString())){
					Toast.makeText(getApplicationContext(), "请先选择曾经留学的国家", Toast.LENGTH_SHORT).show();
				}else{
					showChooseCountryDialog2(getString(R.string.dialog_online_filter_hint_2), peo_city_txt);
				}
			}
		});
		peo_school_txt = (AutoCompleteTextView)findViewById(R.id.peo_school_txt);
		peo_school_txt.setText(OnlineActivity.school);
		peo_school_txt.setHintTextColor(getResources().getColor(R.color.default_light_gray));
		peo_school_txt.addTextChangedListener(new TextWatcher(){
			@Override
			public void afterTextChanged(Editable arg0) {
				long nowTime = System.currentTimeMillis();
				if(nowTime - searchTime > 100){
					searchTime = nowTime;
					RequestParams params = new RequestParams();
					params.put("name", peo_school_txt.getText().toString());
					HttpClient.getInstance().get2(Constants.API_SEARCH_COLLEGE_URL, params, collegeHandler);
				}
			}

			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,
					int arg2, int arg3) {
			}

			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2,
					int arg3) {
			}});
		
		findViewById(R.id.rel_now_in).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				showChooseCountryDialog4(getString(R.string.dialog_online_filter_hint_4), peo_location_txt);
			}
		});
		
		findViewById(R.id.rel_home_town).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				showChooseCountryDialog3(getString(R.string.dialog_online_filter_hint_5),peo_home_town_txt );
			}
		});
		findViewById(R.id.rel_sex).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(OnlineActivity.this,SexSelectActivity.class),101);
			}
		});
		findViewById(R.id.rel_type).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(OnlineActivity.this,TypeSelectActivity.class),102);
			}
		});
		
		findViewById(R.id.rel_group_loc).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				showChooseCountryDialog("群所在地");
			}
		});
		findViewById(R.id.rel_group_type).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(OnlineActivity.this,GroupTypeSelectActivity.class),103);
			}
		});
		
	}
	private void showChooseCountryDialog(String title){
		View inputView = getLayoutInflater().inflate(R.layout.dialog_wheel_1_view, null);
		final WheelView wheel = (WheelView)inputView.findViewById(R.id.wheel_1);
		List<String> countryList = new ArrayList<String>();
		for(CountryData cd:BaseActivity.getCountryList(getApplicationContext())){
			countryList.add(cd.getN());
		}
        wheel.setAdapter(new StringWheelAdapter(countryList));
        wheel.setCurrentItem(1);
        wheel.setCyclic(true);
        wheel.setInterpolator(new AnticipateOvershootInterpolator());
		AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this);
		builder.setTitle(title);
		builder.setView(inputView);  
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){
				int countryIdx = wheel.getCurrentItem();
				search_group_loc = BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getN();
				group_location_txt.setText(search_group_loc);
				group_location_txt.setTextColor(getResources().getColor(R.color.default_black));
			}
		});  
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){}
		}); 
		builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				search_group_loc = "";
				group_location_txt.setText("不限");
				group_location_txt.setTextColor(getResources().getColor(R.color.default_light_gray));
			}
		});
		builder.show();  
	}
	private void showChooseCountryDialog3(String title,final TextView inputEdit3){
		View inputView = getLayoutInflater().inflate(R.layout.dialog_wheel_2_view, null);
		final WheelView wheel1 = (WheelView)inputView.findViewById(R.id.wheel_1);
		final WheelView wheel2 = (WheelView)inputView.findViewById(R.id.wheel_2);
		
		List<String> provinceList = new ArrayList<String>();
		for(ProvinceData cd:BaseActivity.getCountryList(getApplicationContext()).get(0).getP()){
			provinceList.add(cd.getN());
		}
        wheel1.setAdapter(new StringWheelAdapter(provinceList));
        wheel1.setCurrentItem(homeIdx1);
        wheel1.setCyclic(true);
        wheel1.setInterpolator(new AnticipateOvershootInterpolator());
        wheel1.addChangingListener(new OnWheelChangedListener(){
			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				homeIdx1 = newValue;
				homeIdx2 = 0;
				List<String> cityList = new ArrayList<String>();
				for(CityData cd:BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(homeIdx1).getC()){
					cityList.add(cd.getN());
				}
				wheel2.setAdapter(new StringWheelAdapter(cityList));
			}});
        
		List<String> cityList = new ArrayList<String>();
		for(CityData cd:BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(homeIdx1).getC()){
			cityList.add(cd.getN());
		}
        wheel2.setAdapter(new StringWheelAdapter(cityList));
        wheel2.setCurrentItem(homeIdx2);
        wheel2.setCyclic(true);
        wheel2.setInterpolator(new AnticipateOvershootInterpolator());
        
		AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this);
		builder.setTitle(title);
		builder.setView(inputView);  
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){
				homeIdx1 = wheel1.getCurrentItem();
				homeIdx2 = wheel2.getCurrentItem();
				if(TextUtils.isEmpty(BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(homeIdx1).getN())){
					inputEdit3.setText(BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(homeIdx1).getC().get(homeIdx2).getN());
					inputEdit3.setTextColor(getResources().getColor(R.color.default_black));
				}else{
					inputEdit3.setText(BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(homeIdx1).getN()+" "+BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(homeIdx1).getC().get(homeIdx2).getN());
					inputEdit3.setTextColor(getResources().getColor(R.color.default_black));
				}
				home = inputEdit3.getText().toString();
			}
		});  
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){}
		}); 
		builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				inputEdit3.setText("不限");
				homeIdx1 = 0;
				homeIdx2 = 0;
				home = "";
				inputEdit3.setTextColor(getResources().getColor(R.color.default_light_gray));
			}
		});
		builder.show();  
	}
	
	private void showChooseCountryDialog4(String title,final TextView inputEdit4){
		View inputView = getLayoutInflater().inflate(R.layout.dialog_wheel_2_view, null);
		final WheelView wheel1 = (WheelView)inputView.findViewById(R.id.wheel_1);
		final WheelView wheel2 = (WheelView)inputView.findViewById(R.id.wheel_2);
		
		List<String> provinceList = new ArrayList<String>();
		for(ProvinceData cd:BaseActivity.getCountryList(getApplicationContext()).get(0).getP()){
			provinceList.add(cd.getN());
		}
        wheel1.setAdapter(new StringWheelAdapter(provinceList));
        wheel1.setCurrentItem(locIdx1);
        wheel1.setCyclic(true);
        wheel1.setInterpolator(new AnticipateOvershootInterpolator());
        wheel1.addChangingListener(new OnWheelChangedListener(){
			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				locIdx1 = newValue;
				locIdx2 = 0;
				List<String> cityList = new ArrayList<String>();
				for(CityData cd:BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(locIdx1).getC()){
					cityList.add(cd.getN());
				}
				wheel2.setAdapter(new StringWheelAdapter(cityList));
				
			}});
        
		List<String> cityList = new ArrayList<String>();
		for(CityData cd:BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(locIdx1).getC()){
			cityList.add(cd.getN());
		}
        wheel2.setAdapter(new StringWheelAdapter(cityList));
        wheel2.setCurrentItem(locIdx2);
        wheel2.setCyclic(true);
        wheel2.setInterpolator(new AnticipateOvershootInterpolator());
        
		AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this);
		builder.setTitle(title);
		builder.setView(inputView);  
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){
				locIdx1 = wheel1.getCurrentItem();
				locIdx2 = wheel2.getCurrentItem();
				if(TextUtils.isEmpty(BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(locIdx1).getN())){
					inputEdit4.setText(BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(locIdx1).getC().get(locIdx2).getN());
				}else{
					inputEdit4.setText(BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(locIdx1).getN()+" "+BaseActivity.getCountryList(getApplicationContext()).get(0).getP().get(locIdx1).getC().get(locIdx2).getN());
				}
				inputEdit4.setTextColor(getResources().getColor(R.color.default_black));
				loc = inputEdit4.getText().toString();
			}
		});  
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){}
		}); 
		builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				inputEdit4.setText("不限");
				locIdx1 = 0;
				locIdx2 =0;
				inputEdit4.setTextColor(getResources().getColor(R.color.default_light_gray));
				loc = "";
			}
		});
		builder.show();  
	}
	AsyncHttpResponseHandler collegeHandler = new AsyncHttpResponseHandler(){
		@Override
		public void onFailure(Throwable arg0, String result) {
		}

		@Override
		public void onSuccess(String result) {
			if(!TextUtils.isEmpty(result)){
				try{
					Gson gson = new Gson();
					SearchCollegeResponse response = (SearchCollegeResponse)gson.fromJson(result, SearchCollegeResponse.class);
//					System.out.println("---message---"+response.getErrorMsg());
					if(response.getErrNo()!=null && response.getErrNo().equals("0")){
						if(response.getData()!=null && response.getData().size()>0){
							searchCollegeList.clear();
							searchCollegeList.addAll(response.getData());
							
							List<String> collegeNameArray = new ArrayList<String>();
							for(SearchCollegeData scd:searchCollegeList){
								collegeNameArray.add(scd.getName());
							}
							ArrayAdapter<String> av = new ArrayAdapter<String>(OnlineActivity.this,R.layout.include_college_dropdown_item, collegeNameArray);
							peo_school_txt.setAdapter(av);
//							schoolInput.showDropDown();
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
	};
	private void showChooseCountryDialog2(String title,final TextView inputEdit2){
		View inputView = getLayoutInflater().inflate(R.layout.dialog_wheel_2_view, null);
		final WheelView wheel1 = (WheelView)inputView.findViewById(R.id.wheel_1);
		final WheelView wheel2 = (WheelView)inputView.findViewById(R.id.wheel_2);
		
		List<String> provinceList = new ArrayList<String>();
		for(ProvinceData cd:BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP()){
			provinceList.add(cd.getN());
		}
        wheel1.setAdapter(new StringWheelAdapter(provinceList));
        wheel1.setCurrentItem(provinceIdx);
        wheel1.setCyclic(true);
        wheel1.setInterpolator(new AnticipateOvershootInterpolator());
        wheel1.addChangingListener(new OnWheelChangedListener(){
			@Override
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				provinceIdx = newValue;
				cityIdx = 0;
				
				List<String> cityList = new ArrayList<String>();
				for(CityData cd:BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getC()){
					cityList.add(cd.getN());
				}
				wheel2.setAdapter(new StringWheelAdapter(cityList));
				wheel2.setCurrentItem(cityIdx);
			}});
        
		List<String> cityList = new ArrayList<String>();
		for(CityData cd:BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getC()){
			cityList.add(cd.getN());
		}
        wheel2.setAdapter(new StringWheelAdapter(cityList));
        wheel2.setCurrentItem(cityIdx);
        wheel2.setCyclic(true);
        wheel2.setInterpolator(new AnticipateOvershootInterpolator());
        
		AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this);
		builder.setTitle(title);
		builder.setView(inputView);  
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){
				provinceIdx = wheel1.getCurrentItem();
				cityIdx = wheel2.getCurrentItem();
				if(TextUtils.isEmpty(BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getN())){
					if(TextUtils.isEmpty(BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getC().get(cityIdx).getN())){
						inputEdit2.setText(BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getN());
					}else{
						inputEdit2.setText(BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getC().get(cityIdx).getN());
					}
				}else{
					inputEdit2.setText(BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getN()+" "+BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getP().get(provinceIdx).getC().get(cityIdx).getN());
				}
				inputEdit2.setTextColor(getResources().getColor(R.color.default_black));
				city = inputEdit2.getText().toString();
			}
		});  
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){}
		}); 
		builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				inputEdit2.setText("不限");
				provinceIdx = 0;
				cityIdx = 0;
				city = "";
				inputEdit2.setTextColor(getResources().getColor(R.color.default_light_gray));
			}
		});
		builder.show();  
	}
	
	private void showChooseCountryDialog(String title,final TextView inputEdit1,final TextView inputEdit2){
		View inputView = getLayoutInflater().inflate(R.layout.dialog_wheel_1_view, null);
		final WheelView wheel = (WheelView)inputView.findViewById(R.id.wheel_1);
		List<String> countryList = new ArrayList<String>();
		for(CountryData cd:BaseActivity.getCountryList(getApplicationContext())){
			countryList.add(cd.getN());
		}
        wheel.setAdapter(new StringWheelAdapter(countryList));
        wheel.setCurrentItem(countryIdx);
        wheel.setCyclic(true);
        wheel.setInterpolator(new AnticipateOvershootInterpolator());
		AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this);
		builder.setTitle(title);
		builder.setView(inputView);  
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){
				provinceIdx = 0;
				cityIdx = 0;
				inputEdit2.setText("不限");
				inputEdit2.setTextColor(getResources().getColor(R.color.default_light_gray));
				countryIdx = wheel.getCurrentItem();
				inputEdit1.setText(BaseActivity.getCountryList(getApplicationContext()).get(countryIdx).getN());
				inputEdit1.setTextColor(getResources().getColor(R.color.default_black));
				country = inputEdit1.getText().toString();
			}
		});  
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){  
			public void onClick(DialogInterface dialog, int whichButton){}
		}); 
		builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				countryIdx=0;
				inputEdit1.setText("不限");
				inputEdit1.setTextColor(getResources().getColor(R.color.default_light_gray));
				country = "";
			}
		});
		builder.show();  
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if(requestCode == 101){
			if(resultCode ==-1){
				peo_sex_txt.setText("不限");
				peo_sex_txt.setTextColor(getResources().getColor(R.color.default_light_gray));
			}else if(resultCode == 0){
				peo_sex_txt.setText("男");
				peo_sex_txt.setTextColor(getResources().getColor(R.color.default_black));
			}else{
				peo_sex_txt.setText("女");
				peo_sex_txt.setTextColor(getResources().getColor(R.color.default_black));
			}
		}else if(requestCode == 102){
			if(resultCode ==-1){
				peo_type_txt.setText("不限");
				peo_type_txt.setTextColor(getResources().getColor(R.color.default_light_gray));
			}else if(resultCode == 0){
				peo_type_txt.setText("只看国外留学生");
				peo_type_txt.setTextColor(getResources().getColor(R.color.default_black));
			}else if(resultCode == 1){
				peo_type_txt.setText("只看海归留学生");
				peo_type_txt.setTextColor(getResources().getColor(R.color.default_black));
			}else{
				peo_type_txt.setText("只看想要出国的");
				peo_type_txt.setTextColor(getResources().getColor(R.color.default_black));
			}
		}else if(requestCode == 103){
			if(resultCode ==-1){
				group_type_txt.setText("不限");
				group_type_txt.setTextColor(getResources().getColor(R.color.default_light_gray));
			}else if(resultCode == 0){
				group_type_txt.setText("出国交流");
				group_type_txt.setTextColor(getResources().getColor(R.color.default_black));
			}else if(resultCode == 1){
				group_type_txt.setText("海龟交流");
				group_type_txt.setTextColor(getResources().getColor(R.color.default_black));
			}else{
				group_type_txt.setText("国外交流");
				group_type_txt.setTextColor(getResources().getColor(R.color.default_black));
			}
		}
	}

	private class ListViewAdapter1 extends BaseAdapter{
		public int pageIdx = 1;
		public boolean hasMore = true;
		private SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		private Gson gson = new Gson();
		
		private static final int TYPE_ITEM = 0;
		private static final int TYPE_SEPARATOR = 1;
		private List<UserInfoData> datas;
		
		public void setData(List<UserInfoData> data){
			this.datas = data;
		}
		
		@Override
		public int getCount() {
			return datas.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}
		

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			
			if(convertView==null){
				convertView = getLayoutInflater().inflate(R.layout.include_online_list_item, null);
			}
			UserInfoData userData = datas.get(position);
			TextView itemName = (TextView)convertView.findViewById(R.id.item_name);
			itemName.setText(userData.getuName());
			TextView itemCountry = (TextView)convertView.findViewById(R.id.item_country);
//			itemCountry.setText(sdf.format(new Date(Long.parseLong(userData.getuTS())*1000)));
			TextView universityText = (TextView)convertView.findViewById(R.id.item_university);
//			universityText.setText(userData.getuConstellation());
			TextView itemSign = (TextView)convertView.findViewById(R.id.item_signature);
			itemSign.setText(userData.getuSign());
			
			TextView itemDistance =(TextView)convertView.findViewById(R.id.item_distance);
			//itemDistance.setText(userData.getU)
			ImageView item_now = (ImageView)convertView.findViewById(R.id.item_now);
			
			if(!TextUtils.isEmpty(userData.getuLocDetail())){
//				System.out.println("---uid---"+userData.getuId());
//				System.out.println("---locdetail---"+userData.getuLocDetail());
				MyLocationInfo locInfo = gson.fromJson(userData.getuLocDetail(), MyLocationInfo.class);
				if(locInfo.getType().equals("PlanGoOut")){
					universityText.setText(locInfo.getToschool());
					itemCountry.setText("中国 "+locInfo.getCity());
				}else if(locInfo.getType().equals("Returnees")){
					if(!TextUtils.isEmpty(locInfo.getSchool2())){
						universityText.setText(locInfo.getSchool1()+","+locInfo.getSchool2());
					}else{
						universityText.setText(locInfo.getSchool1());
					}
					itemCountry.setText(locInfo.getLoc());
				}else{
					universityText.setText(locInfo.getSchool());
					itemCountry.setText(locInfo.getCity()+" "+locInfo.getCountry());
				}
			}
			if(userData.getuLocType().equals("1")){
				item_now.setImageResource(R.drawable.inchina);
			}else if(userData.getuLocType().equals("2")){
				item_now.setImageResource(R.drawable.goabroad);
			}else{
				item_now.setImageResource(R.drawable.abroad);
			}
			TextView genderText = (TextView)convertView.findViewById(R.id.item_gender_text);
			ImageView genderImage = (ImageView)convertView.findViewById(R.id.item_gender);
			if(userData.getuGender().equals("0")){
				genderImage.setImageResource(R.drawable.online_male);
				genderText.setText(userData.getuAge());
			}else{
				genderImage.setImageResource(R.drawable.online_female);
				genderText.setText(userData.getuAge());
			}
			if(userData.getDistance()!=null && !userData.getDistance().equals("0")){
				System.out.println("Distance :"+userData.getDistance());
				int distance = Integer.parseInt(userData.getDistance())/1000;
				((TextView)convertView.findViewById(R.id.item_distance)).setText(distance+"km");
			}else{
				//convertView.findViewById(R.id.item_distance).setVisibility(View.GONE);
				((TextView)convertView.findViewById(R.id.item_distance)).setText("未知");
				//convertView.findViewById(R.id.dddd).setVisibility(View.GONE);
			}
			RoundImageView itemImage = (RoundImageView)convertView.findViewById(R.id.item_image);
			if(!TextUtils.isEmpty(userData.getuIcon())){
				String endStr = userData.getuIcon().substring(userData.getuIcon().lastIndexOf("."));
				imageLoader.displayImage(Constants.IMAGE_PHOTO_SERVER_PATH+userData.getuIcon().replace(endStr, "_150_150"+endStr), itemImage, options);
//				imageLoader.displayImage(Constants.IMAGE_PHOTO_SERVER_PATH+userData.getuIcon(), itemImage, options);
			}else{
				itemImage.setImageResource(R.drawable.default_user_logo);
			}
			return convertView;
		}		
	}
}
